<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        let channel = new MessageChannel()
        let port1 = channel.port1;
        let port2 = channel.port2;
        port1.onmessage = function (event) {
            debugger;
            console.log('port1收到来自post2的数据', event.data)
        }
        port2.onmessage = function (event) {
            console.log('port2收到来自port1的数据', event.data)
        }
        port1.postMessage('发送给port2')
        port2.postMessage('发送给port1')
    </script>
</body>

</html>